package org.four.web.consumer;

import com.rabbitmq.client.Channel;
import lombok.extern.slf4j.Slf4j;
import org.four.common.model.ZhaoPinBean;
import org.four.web.conf.DelayRabbitConfig;
import org.four.web.service.ZslService;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.stereotype.Component;

import java.util.Date;

@Component
@Slf4j
public class DelayReceiver {

    @Autowired
    private ZslService zslService;

    @RabbitListener(queues = {DelayRabbitConfig.ORDER_QUEUE_NAME})
    public void orderDelayQueue(ZhaoPinBean order, Message message, Channel channel) {
        log.info("###########################################");
        log.info("【orderDelayQueue 监听的消息】 - 【消费时间】 - [{}]- 【订单内容】 - [{}]",  new Date(), order.toString());
        ZhaoPinBean zhaoPinBean = zslService.queryById(order.getId());
        if(zhaoPinBean.getZhidingTime()!=null) {
            zslService.updateTime(zhaoPinBean.getId());
            log.info("到期了");
        } else{
            log.info("没期了");
        }
    }
}
